package com.jerei.store.controller;

import com.jerei.store.controller.ex.*;
import com.jerei.store.service.ex.*;
import com.jerei.store.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler({ServiceException.class, FileUploadException.class})
    public JsonResult<Void> handleException(Throwable ex){
        JsonResult<Void> json=new JsonResult<>(ex);
        if(ex instanceof UsernameDuplicationException){
            json.setState(4000);
        }else if(ex instanceof UserNotFoundException){
            json.setState(4001);
        }else if(ex instanceof PasswordNotMatchException){
            json.setState(4002);
        }else if (ex instanceof AddressCountLimitException){
            json.setState(4003);
        }else if(ex instanceof SelectException){
            json.setState(4004);
        } else if (ex instanceof DeleteException) {
            json.setState(4005);
        } else if (ex instanceof InsertException) {
            json.setState(5000);
        } else if (ex instanceof UpdateException) {
            json.setState(5001);
        } else if (ex instanceof FileEmptyException) {
            json.setState(6000);
        } else if (ex instanceof FileSizeException) {
            json.setState(6001);
        } else if (ex instanceof FileTypeException) {
            json.setState(6002);
        } else if (ex instanceof FileUploadStateException) {
            json.setState(6003);
        } else if (ex instanceof FileUploadIOException) {
            json.setState(6004);
        }
        return json;
    }




}
